{#% extends '/ic/dashboard.html' %#}
{% block content %}
    <div class="row">
        <br/>
        {% if pageData["oper"] and pageData["oper"].tipo_operatore|lower == "amministratore" %}
        <div class="col-xs-12 col-md-12 col-lg-12 col-sm-12">
            {% if pageData["tipo"] == "eventi" %}
                <a type="button" tipo_dao='{{pageData["tipo"]}}' class="btn btn-success col-xs-12 col-sm-12 col-lg-12 centered new_dao">Aggiungi un evento</a>
            {% else %}
                <a type="button" class="btn btn-info col-xs-12 col-sm-12 col-lg-12 centered new_dao">Aggiungi una News</a>
            {% endif %}
        </div>
        {% endif %}
    </div>
              <br/>
<div class="Edit_dao"></div>

<div class="infinite-container2">
    {% for news in pageData['newss'] %}
    <div class="infinite-item2">
    <div class="row">
        <div class="col-xs-12 col-md-12 col-lg-12 col-sm-12">
        {% if news.tipo_news|lower == "eventi" and pageData["tipo"]|lower =="eventi" %}<!-- EVENTI -->
            <div class="panel panel-success">
                <div class="panel-heading">
                    [{{news.tipo_news}}]<strong>{{news.title}}</strong>
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-sm-12 col-lg-12">{{ news.body }}</div>
                     </div>
                </div>
                <div style="font-size:0.90em;margin-right:-20px;" class="panel-footer">
                   {% if pageData["oper"] and pageData["oper"].tipo_operatore|lower == "amministratore" %}
                        Del: {{news.publication_date|dateformat}}
                   {% else %}
                        Del: {{news.publication_date|datetimeformat}}
                   {% endif %}
                    {% if pageData["oper"] and pageData["oper"].tipo_operatore|lower == "amministratore" %}
                        <a  href="/italiaCives/news/delete?id={{news.id}}" onclick="return confirm('Sei sicuro di voler cancellare questo evento?');" type="button" class="btn pull-right"><i style="color:#449D44;margin-top:-15px;" class="fa fa-trash fa-2x"></i></a> <!-- DELETE EVENTI -->
                        <a type="button" tipo_dao='{{pageData["tipo"]}}' id_dao ={{ news.id }} class="btn pull-right edit_dao"><i style="color:#449D44;margin-top:-15px;" class="fa fa-edit fa-2x"></i></a><!-- EDIT EVENTI -->
                      {% endif %}
                </div>
            </div>
        {% elif news.tipo_news|lower != "eventi" and pageData["tipo"]|lower != "eventi" %} <!-- TUTTO IL RESTO, NEWS -->
            <div class="panel panel-info">
                <div class="panel-heading">
                    [{{news.tipo_news}}]<strong>{{news.title}}</strong>
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-sm-12 col-lg-12"><p>{{ news.body }}</p></div>
                     </div>

                </div>
                <div style="font-size:0.90em;margin-right:-20px;" class="panel-footer">
                    {% if pageData["oper"] and pageData["oper"].tipo_operatore|lower == "amministratore" %}
                   Del: {{news.publication_date|dateformat}}
                   {% else %}
                    Del: {{news.publication_date|datetimeformat}}
                   {% endif %}
                   {% if pageData["oper"] and pageData["oper"].tipo_operatore|lower == "amministratore" %}
                        <a  href="/italiaCives/news/delete?id={{news.id}}" onclick="return confirm('Sei sicuro di voler cancellare questa news?');" type="button" class="btn pull-right"><i style="color:#31B0D5;margin-top:-15px;" class="fa fa-trash fa-2x"></i></a> <!-- DELETE NEWS -->
                        <a type="button" id_dao ={{ news.id }} class="btn pull-right edit_dao"><i style="color:#31B0D5;margin-top:-15px;" class="fa fa-edit fa-2x"></i></a> <!-- EDIT NEWS -->
                    {% endif %}
                </div>
            </div>
        {% endif %}
        </div>
    </div>
    </div>
    {% endfor %}
{% if pageData['page'] != 0 %}
    {% if pageData["tipo"]|lower =="eventi" %}
        <a href="/italiaCives/news/{{pageData['page']}}?tipo={{pageData['tipo']}}" class="infinite-more-link2"></a>
    {% else %}
        <a href="/italiaCives/news/{{pageData['page']}}" class="infinite-more-link2"></a>
    {% endif %}
{% endif %}
</div>

{% endblock%}
{% block custom_js %}
<script type="text/javascript">
$(document).ready(function () {
    $(".Edit_dao").hide()

    $(".infinite-container2" ).on( "click",".edit_dao", function(e){
        e.preventDefault()
        window.scrollTo(90, 90);
        $('.Edit_dao').toggle(400);
        $(".infinite-container2").toggle(400);
        var id_dao = $(this).attr("id_dao");
        var tipo_dao = $(this).attr("tipo_dao");
        $('.Edit_dao').load('/italiaCives/news/add',{"tipo":tipo_dao, "id":id_dao});
          });

    //$(".infinite-container2" ).on( "click",".edit_dao_news", function(e){
        //e.preventDefault()
        //$('.Edit_dao').toggle(400);
        //$(".infinite-container2").toggle(400);
        //var id_dao = $(this).attr("id_dao");
        //$('.Edit_dao').load('/italiaCives/news/Edit',{"id":id_dao});
          //});


    $('.infinite-container2').waypoint('infinite', {
      container: 'auto',
      items: '.infinite-item2',
      more: '.infinite-more-link2',
      offset: 'bottom-in-view',
      loadingClass: 'infinite-loading',
      onBeforePageLoad: $.noop,
      onAfterPageLoad: $.noop
    });
    $(window).trigger('resize');
    $.waypoints('refresh');
    $.waypoints('viewportHeight');
    //$('.infinite-container3').waypoint('disable');
    $('.infinite-container3').empty()

    $(".new_dao").click(function(e){
        e.preventDefault()
        $('.Edit_dao').toggle(400);
            $(".infinite-container2").toggle(400);
            var tipo_dao = $(this).attr("tipo_dao");
            $('.Edit_dao').load('/italiaCives/news/add?tipo=eventi',{"tipo":tipo_dao});
          });

    //$(".new_dao_new").click(function(e){
        //e.preventDefault()
        //$('.Edit_dao').toggle(400);
            //$(".infinite-container2").toggle(400);
            //$('.Edit_dao').load('/italiaCives/news/add');
          //});


    //$("#new_dao_news").click(function(e){
        //e.preventDefault()
        //$('.Edit_dao').toggle(400);
            //$(".infinite-container2").toggle(400);
            //$('.Edit_dao').load('/italiaCives/news/add');
          //});



});
</script>
{% endblock%}
